package vcp.models;

import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.ArrayList;
import java.util.Observable;

import client.Message;
import control.SimpleClient;
import db.parking.beans.Orders;
import db.parking.beans.QuarterReports;
import vcp.common.AbstractModel;

/**
 * Reports Model
 *
 */
public class ReportsModel extends Observable implements PropertyChangeListener {
	protected SimpleClient client = null;
	protected Message msg = null;

	/**
	 * create Quarter Report request
	 * @param reports
	 */
	public void createQuarterReport(QuarterReports reports) {
		client = SimpleClient.getInstance();
		client.addPropertyChangeListener(this);

		Message msg = new Message(reports, "CreateQuarterReport");
		try {
			client.sendToServer(msg);
		} catch (Exception ex) {
			System.out.println(ex.toString() + " ->CreateQuarterReport");
		}
	}

	/**
	 * get Quarter Report request
	 * @param reports
	 */
	public void getQuarterReport(QuarterReports reports) {
		client = SimpleClient.getInstance();
		client.addPropertyChangeListener(this);

		Message msg = new Message(reports, "GetQuarterReport");
		try {
			client.sendToServer(msg);
		} catch (Exception ex) {
			System.out.println(ex.toString() + " ->GetQuarterReport");
		}

	}

	/**
	 * get parking lot object request
	 */
	public void getPlObject() {
		client = SimpleClient.getInstance();
		client.addPropertyChangeListener(this);
		Message msg = new Message(null, "GetParkingObject");
		try {
			client.sendToServer(msg);
		} catch (Exception ex) {
			System.out.println(ex.toString()
					+ "->GetParkingObject");
		}
	}

	/**
	 * get Lot By Lot Num request
	 * @param lotNum
	 */
	public void getLotByLotNum(int lotNum) {
		client = SimpleClient.getInstance();
		client.addPropertyChangeListener(this);
		Message msg = new Message(lotNum, "GetLotByLotNum");
		try {
			client.sendToServer(msg);
		} catch (Exception ex) {
			System.out.println(ex.toString()
					+ "->GetLotByLotNum");
		}

	}
	
	/**
	 * get monthly report request
	 * @param arr
	 */
	public void getMonthlyReport(ArrayList<Object> arr) {
		client = SimpleClient.getInstance();
		client.addPropertyChangeListener(this);
		Message msg = new Message(arr, "GetMonthlyReport");
		try {
			client.sendToServer(msg);
		} catch (Exception ex) {
			System.out.println(ex.toString()
					+ "->GetMonthlyReport");
		}
	}
	
	
	@Override
	public void propertyChange(PropertyChangeEvent event) {
		if (event.getPropertyName().equals("MessageUpdate")) {	
			msg = client.getReturnMsg();
			
			setChanged();
			notifyObservers(msg);
        }
	
		client.clearPropertyChangeListener();
	}

	

}
